package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class dataUtil {
	
	public static Connection conn;
	public static String Data = "jdbc:sqlserver://thanhsiel;DATABASENAME=crimefile";
	public static String USER_NAME = "sa";
	public static String PASSWORD ="siel0909";
	
	public static void connect() {
		
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn = DriverManager.getConnection(Data, USER_NAME, PASSWORD);
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	public static Connection getconnConnection() {
		if(conn == null) {
			connect();
		}
		return conn;
	}
	public static ResultSet executeQuery(String sql) {
		try{
		connect();
		Statement statement = conn.createStatement();
		ResultSet rs = statement.executeQuery(sql);
		return rs;
		}catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	public static Boolean executeNonQuery(String sql) {
		try {
			connect();
			Statement statement = conn.createStatement();
			statement.executeUpdate(sql);
			return true;
		} catch (SQLException e2) {
			e2.printStackTrace();
			return false;
		}
	}

}


